﻿@{
    Layout = null;
}
@using KingRoad.EPM.Common.Helper
<script type="text/javascript">
    var Details_jqgrid_lastID = 0; //最后一次选中的行ID
    var Details_edit_url = "/Permission/Items/DetailsEdit/@ViewBag.ItemID"; //编辑路径
    $(document).ready(function () {
        DetailsGridGet();
        $("#Permission_Items_DetailsDelete").bind("click", function () {
            return Details_Delete();
        });
        $("#Permission_Items_DetailsCreate").attr("href", "/Permission/Items/DetailsCreate/@ViewBag.ItemID");

    });

    function DetailsGridGet() {
        $("#DetailsTable").jqGrid({
            url: "/Permission/Items/GetDetails/@ViewBag.ItemID",
            ajaxGridOptions: { contentType: 'application/json; charset=utf-8' },
            datatype: "json",
            treeGrid: true,
            ExpandColumn: "ItemCode",
            treeGridModel: 'adjacency',
            mtype: "GET",
            colNames: ['ID', '编号', '名称', '值', '有效', '描述'],
            colModel: [
                        { name: 'Id', index: 'Id', width: 1, key: true, align: "center", sortable: false, hidden: true },
                        { name: 'ItemCode', index: 'ItemCode', width: 350, align: "center", sortable: false },
                        { name: 'ItemName', index: 'ItemName', width: 250, align: "center", sortable: false },
                        { name: 'ItemValue', index: 'ItemValue', width: 150, align: "center", sortable: false },
                        { name: 'Enabled', index: 'Enabled', width: 100, align: "center", formatter: "checkbox", sortable: false },
                        { name: 'Description', index: 'Description', width: 150, align: "center", sortable: false }
                       ],
            loadError: function (xhr, status) {
                alertMsg.error(xhr.responseText);
            },
            loadComplete: function (xhr) {
                var ajaxbg = $("#background,#progressBar,#lui_DetailsTable");
                ajaxbg.hide();
            },
            onSelectRow: Details_OnSelectRow,
            rownumbers: false,
            autowidth: true,
            shrinkToFit: true,
            multiselect: false,
            multiselectWidth: 50,
            sortable: false,
            viewrecords: true,
            sortorder: "desc",
            rowNum: -1,
            jsonReader: {
                repeatitems: false
            },
            height: 387
        });
    }

    function Details_OnSelectRow(rowid, status) {

        var tempID = $("#DetailsTable").getCell(rowid, "Id");
        Details_jqgrid_lastID = tempID;

        $("#Permission_Items_DetailsCreate").attr("href", "/Permission/Items/DetailsCreate/" + $("#Permission_Details_itemID").val() + "?detailID=" + tempID);
        $("#Details_edit").attr("href", Details_edit_url + "?selectId=" + tempID.toString());
    }


    //对选项字典执行删除操作
    function Details_Delete() {
        if (Details_jqgrid_lastID == 0) {
            alertMsg.error("至少要勾选一条记录！");
            return false;
        }
        else {
            alertMsg.confirm("您确定要删除吗？", {
                okCall: function () {
                    var selectId = Details_jqgrid_lastID; // $("#DetailsTable").getCell(rowid, "Id")

                    var Permission_Details_itemID = $("#Permission_Details_itemID").val();

                    $.post("/Permission/Items/DetailsDelete", { "DetailsArryID": selectId, "itemID": Permission_Details_itemID }, DetailsdialogDeleted, "json");
                }
            });
        }
    }

    function DetailsdialogDeleted(json) {
        //提交回调
        //1 接收参数 2 判断成功与否 3 根据返回的数据在树上新增节点
        DWZ.ajaxDone(json);
        if (json.statusCode == DWZ.statusCode.ok) {
            //更新成功
            var Jqgrid_ListID = $("#DetailsTable").jqGrid("getGridParam", "selrow").toString();
            $("#DetailsTable").delRowData(Jqgrid_ListID);
            Details_jqgrid_lastID = 0;
        }

    }

    function DetailsdialogCreating(json) {
        //提交回调
        //1 接收参数 2 判断成功与否 3 根据返回的数据在树上新增节点
        DWZ.ajaxDone(json);
        if (json.statusCode == DWZ.statusCode.ok) {
            //更新成功
            $("#DetailsTable").trigger("reloadGrid");
            Details_jqgrid_lastID = 0;
        }

        $.pdialog.closeCurrent();
        $("#background,#progressBar,#lui_DetailsTable").hide();
    }

    function DetailsdialogEditing(json) {
        //提交回调
        //1 接收参数 2 判断成功与否 3 根据返回的数据在树上新增节点
        DWZ.ajaxDone(json);
        if (json.statusCode == DWZ.statusCode.ok) {
            //更新成功
            $("#DetailsTable").trigger("reloadGrid");
            Details_jqgrid_lastID = 0;
        }
        $.pdialog.closeCurrent();
        $("#background,#progressBar,#lui_DetailsTable").hide();
    }



    function CancelSelect() {
        $("#Permission_Items_DetailsCreate").attr("href", "/Permission/Items/DetailsCreate/" + $("#Permission_Details_itemID").val());
        Details_jqgrid_lastID = 0;
    }

    //实现模糊查询
    $().ready(function () {
        $("#txtkeyword_Permission_Details_Index").keyup(
        function () {
            $("#DetailsTable tr:gt(0)").hide();
            var $d = $("#DetailsTable tr:gt(0)").filter(":contains('" + $.trim($("#txtkeyword_Permission_Details_Index").val()) + "')");
            $d.show();
        }
      )
    })
</script>
<div class="pageContent" layouth="5">
    @*顶部按钮*@
    <div class="panelBar" style="border-top: none;">
        <ul class="toolBar">
            <li class="nobg">关键字:<input type="text" id="txtkeyword_Permission_Details_Index" />
            </li>
            <li>@Html.PermissionButton("DetailsCreate", "Permission_Items_DetailsCreate", "add", "", "Details_Create", "dialog", "添加选项", "true", "400", "320", "添加")</li>
            <li>@Html.PermissionButton("", "Permission_Items_DetailsDelete", "edit", "javascript:void(0)", "", "", "", "true", "删除")</li>
            <li>@Html.PermissionButton("Edit", "Details_edit", "delete", "/Permission/Items/Edit/{sid_Details}", "", "dialog", "修改选项", "true", "400", "320", "修改")</li>
            <li>@Html.PermissionButton("", "Permission_Items_DetailsDelete", "edit", "javascript:CancelSelect();", "", "", "", "true", "取消选择")</li>
        </ul>
    </div>
    <div id="Permission_Details_mainContent">
        <input type="hidden" id="Permission_Details_itemID" value="@ViewBag.ItemID" />
        <table id="DetailsTable">
        </table>
        <div id="Permission_Details_pager">
        </div>
    </div>
</div>
